import Layout from '../../layout/index.vue'

let modules = import.meta.glob('../../views/**/*.vue') //匹配文件
function modifyRoute(list) {
    return list.map((item, index) => {
        item.meta = {
            title: item.name,
        }
        let div = ''
        if (item.pid != 0) {
            div = modules[`../../views${item.path}.vue`]

        } else {
            div = Layout
        }
        return {
            meta: item.meta,
            component: div,
            name: item.name || '/',
            path: item.path || '/',
            children: item.children ? modifyRoute(item.children) : []
        }
    })
}

export default {
    namespaced: true,
    state() {
        return {
            RouterMenu: [],
        }
    },
    mutations: {
        getRouterMenu(state, n) {
            state.RouterMenu = n
        },
    },
    actions: {
        getRouterMenu(context, n) {
            return new Promise(resolve => {
                context.commit('getRouterMenu', n)
                let Meun = modifyRoute(n)
                resolve(Meun)
            })
        },
    },
    getters: {

    }
}